﻿using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
using Project.Yan.Net.DAL.Entities;
using Project.Yan.Net.Tool.Ex;

namespace Project.Yan.Net.DAL
{
    public class UserRepository : Repository<User>, IUserRepository
    {
        /// <summary>
        /// 
        /// </summary>
        public UserRepository(AppDbContext context) : base(context)
        {

           
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task<User?> GetUserByEmailAsync(string email)
        {
            try
            {
                return await base._context.Users.FirstOrDefaultAsync(u => u.Email == email);
            }
            catch (SqlException ex)
            {
                throw new DataAccessException("数据库访问失败，请稍后重试。", CodeEnums.服务错误, ex);
            }
        }
    }
}

